<?php


if (!isset($_REQUEST['t'])) {
	return;
}
$time = $_REQUEST['t'];
//$time = "2012-09-25 18:00:00";

try {
	$m = new Mongo('10.243.118.141');
} catch ( MongoConnectionException $e ) {
	echo '<p class="red">Couldn\'t connect to mongodb, is the "mongo" process running?</p>';
	exit();
}
$c = $m->selectDB('test')->selectCollection('app_log_data');
$fields = array('time_stamp', 'message', 'log_level');
$criteria = array('time_stamp' => array('$gte' => new MongoDate(strtotime($time))));
//var_dump($criteria);

$sort = array('time_stamp' => -1);

$cursor = $c->find($criteria, $fields)->sort($sort);
//var_dump($cursor->count(true));

$i = 0;
foreach ($cursor as $obj) {
	if ($i++ == 0) {
		echo '<input type="hidden" value="'.date('Y-m-d H:i:s',$obj['time_stamp']->sec+1).'">';
	}
	echo '<p><span>'.date('Y-m-d H:i:s',$obj['time_stamp']->sec).'</span>'
			.printBlank(4).'<span class="">['.$obj['log_level'].']</span>'
					.printBlank(4).'<span>'.$obj['message'].'</span></p>';
}

$m->close();

function printBlank($num) {
	$str = '';
	for ($i=0; $i<$num; $i++) {
		$str = $str.'&nbsp;';
	}
	return $str;
}
?>